
%pick up the best classifier

top_num = 1;

% sum_F = zeros( 1, classifier_n );
% 
% for i = 1:length(data_base)
%     sum_F = sum_F + sum(data_base{i}.Fmatrix);
% end
% 
% [~,sort_id] = sort( sum_F );
% 
% pick_id = sort_id(end-top_num+1:end);

pick_id = [1:8];

%append edge

edge_set = [];

bo = zeros(1, classifier_n);
bo( pick_id ) = 1;

for i = find( bo==0 )
    for j = pick_id  
        if(rand()<0.6)
            edge_set = [edge_set ; i j];        
        end
    end
end

for j = pick_id
    for i = pick_id( pick_id~=j )
        edge_set = [edge_set ; i j];        
    end
end

data_base{1}.edge_set = edge_set;

clear bo
        

% start to build corr feature 

edge_n = size( edge_set,1 );

%review the folder is res_root

h = [];

for base_id = 1:length(data_base)
    data_base{ base_id }.recommend_matrix = ...
        zeros( data_base{ base_id }.frame_n, edge_n);            
    
    
    for edge_id = 1: edge_n
        disp( [ num2str(edge_id) ' / ' num2str( edge_n ) ] )
        
        if ~IF_SERVER
            h = imagesc(data_base{ base_id }.recommend_matrix);
            drawnow;        
        end
        
        for frame_id = 1:data_base{ base_id }.frame_n
            fname1 = [ res_root global_prefix data_base{ base_id }.name ...
                       '_' feature_code '_' ...
                       num2str( frame_id-1 ) '_' ...
                       'c' num2str( edge_set( edge_id ,1 )-1 ) '.jpg'];
            fname2 = [ res_root global_prefix data_base{ base_id }.name ...
                       '_' feature_code '_' ...
                       num2str( frame_id-1 ) '_' ...
                       'c' num2str( edge_set( edge_id ,2 )-1 ) '.jpg'];
            res1 = imread( fname1 );            
            res1 = im2double(res1);            
            res2 = imread( fname2 );
            res2 = im2double(res2);
            
            vali = getValidator(res1,res2);
            
            data_base{ base_id }.recommend_matrix( frame_id,edge_id ) ...
                 = vali.F1;
            
            
            % have a vilidate function here
            
        end
        
    end
    
end

%start to save data

save( data_base_save_name, 'data_base')